package 竞赛.NO_406;

import java.util.HashMap;
import java.util.Map;

/**
 * 100368. 从链表中移除在数组中存在的节点
 * 创建时间：2024/7/14 上午11:00
 */
public class 从链表中移除在数组中存在的节点_100368 {
    public ListNode modifiedList(int[] nums, ListNode head) {
        Map<Integer, Integer> map = new HashMap<>();
        ListNode ans = new ListNode();
        for (int num : nums) {
            map.put(num, 1);
        }
        ListNode cur = head;
        ListNode tmp = ans;
        while (cur != null) {
            Integer val = map.get(cur.val);
            if (val != 1) {
                tmp.next = new ListNode(cur.val);
                tmp = tmp.next;
            }
            cur = cur.next;
        }
        return ans.next;
    }

    public static void main(String[] args) {

    }
}

class ListNode {
      int val;
      ListNode next;
      ListNode() {}
      ListNode(int val) { this.val = val; }
      ListNode(int val, ListNode next) { this.val = val; this.next = next; }
  }
